#include "binaryTree.h"

#include "stack.h"

Status InitStack(SqStack *stack)
{
    stack->base = (Elemtype *)malloc(MAXSIZE * sizeof(Elemtype));
    if (!stack->base)
    {
        return 0;
    }
    stack->top = stack->base;
    stack->stackSize = MAXSIZE;
    return 1;
}

Status DestroyStack(SqStack *stack)
{
    free(stack->base);
    stack->base = NULL;
    stack->top = NULL;
    stack->stackSize = 0;
    return 1;
}
bool StackEmpty(SqStack stack)
{
    return stack.base == stack.top;
}
bool StackFull(SqStack stack)
{
    return stack.top - stack.base == stack.stackSize;
}
Status Push(SqStack *stack, Elemtype e)
{
    if (StackFull(*stack))
    {
        return 0;
    }
    *(stack->top) = e;
    stack->top++;
    return 1;
}
Status Pop(SqStack *stack, Elemtype *e)
{
    if (StackEmpty(*stack))
    {
        return 0;
    }
    stack->top--;
    *e = *(stack->top);
    return 1;
}
